package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.POIUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

//
@RestController
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    //  文件上传   /ordersetting/upload

    @RequestMapping("/ordersetting/upload")
    public Result upload(@RequestParam("excelFile") MultipartFile excelFile){
        try {
            List<String[]> excelList = POIUtils.readExcel(excelFile);
            orderSettingService.upload(excelList);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.IMPORT_ORDERSETTING_FAIL);
        }
        return new Result(false,MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
    }

    //  /ordersetting/getOrderSettingByMonth
    // 根据年份和月份查询预约数据   ,格式： yyyy-MM

    @RequestMapping("/ordersetting/getOrderSettingByMonth")
    public Result  getOrderSettingByMonth(String date){
        return orderSettingService.getOrderSettingByMonth(date);
    }

    // /ordersetting/editNumberByDate
    // 因为 是 yyyy/MM/dd是这种形式 ，而我们传送过来是 yyyy-MM-dd，所以要进行转换(通过注解或者是xml中进行修改)
    // SpringMVC的配置文件中  <value>WriteDateUseDateFormat</value> 就进行了转换
    @RequestMapping("/ordersetting/editNumberByDate")
    public Result  editNumberByDate(@RequestBody OrderSetting orderSetting){
        return orderSettingService.editNumberByDate(orderSetting);
    }



}
